package com.ning.ems.controller;

import com.ning.ems.dto.PackageAddDto;
import com.ning.ems.dto.PackageListDto;
import com.ning.ems.dto.PackageMyListDto;
import com.ning.ems.entity.Package;
import com.ning.ems.service.PackageService;
import com.ning.ems.vo.PackageVo;
import com.ning.ems.vo.TableData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author Ning 242741154@qq.com
 * @date 2020/4/11 18:29
 */
@Api(tags = "包裹管理相关接口")
@RestController
@RequestMapping("/pkg")
public class PackageController {
    private final PackageService packageService;

    public PackageController(PackageService packageService) {
        this.packageService = packageService;
    }

    @ApiOperation("包裹列表")
    @PostMapping("/list")
    public TableData<PackageVo> list(@RequestBody @Valid PackageListDto info) {
        return packageService.pkgList(info);
    }

    @ApiOperation("个人包裹数量")
    @GetMapping("/myCnt")
    public Integer myList(@RequestParam(value = "user") Integer user) {
        return packageService.myCnt(user);
    }

    @ApiOperation("个人包裹列表")
    @PostMapping("/myList")
    public TableData<PackageVo> myList(@RequestBody @Valid PackageMyListDto info) {
        return packageService.myList(info);
    }

    @ApiOperation("通过 id 查询包裹")
    @GetMapping("/get")
    public PackageVo get(@RequestParam(value = "id") Integer id) {
        return packageService.get(id);
    }

    @ApiOperation("添加包裹")
    @PostMapping("/add")
    public Package add(@RequestBody @Valid PackageAddDto info) {
        return packageService.add(info);
    }

    @ApiOperation("通过 id 删除包裹")
    @DeleteMapping("/add")
    public boolean delete(Integer id) {
        return packageService.delete(id);
    }

}
